
using BuildingBlocks.Presentation.Endpoints;
using BuildingBlocks.Presentation.Results;
using Mediator;

namespace Basket.Api.Features.Baskets.GetBasket;

internal sealed class GetBasketEndpoint : IEndpoint
{
    public void MapEndpoint(IEndpointRouteBuilder app)
    {
        app.MapGet($"{BasketRoutes.Base}",
                async (IMediator mediator, CancellationToken cancellationToken) =>
                {
                    var result = await mediator.Send(new GetBasketQuery(), cancellationToken);
                    return result.Match(Results.Ok, ApiResponse.Problem);
                })
            .WithName("GetBasket")
            .WithTags("Basket");
    }
}
